package com.accompany.config;
 
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
/**
 * Swagger 配置
 * <p>
 * Spring Doc FAQ: https://springdoc.org/#faq
 *
 * @author DC
 * @date 2024/12/26
 */
@Configuration
public class SwaggerConfig {
 
    private static final String TOKEN_HEADER = "Authorization";
 
    /**
     * 接口信息
     */
    @Bean
    public OpenAPI apiInfo() {
        return new OpenAPI()
                .components(
                        new Components().addSecuritySchemes(TOKEN_HEADER,
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.APIKEY)
                                        // 这里配置 bearer 后，你的请求里会自动在 token 前加上 Bearer
                                        .scheme("bearer")
                                        .bearerFormat("JWT")
                        ).addParameters(TOKEN_HEADER,
                                new Parameter()
                                        .in("header")
                                        .schema(new StringSchema())
                                        .name(TOKEN_HEADER)
                        ))
                .info(new Info()
                        .title("apany项目接口文档")
                        .version("1.0.0")
                        .description("apany项目接口文档,用于查看接口")
                        .license(new License().name("Apache 2.0")
                                .url("https://www.baidu.tech"))
                )// 引入外部的文档，我这里引得是 springdoc 官方文档地址，你可以不配此项
                .externalDocs(new ExternalDocumentation()
                        .description("SpringDoc Full Documentation")
                        .url("https://springdoc.org/")
                );
    }
 
    /**
     * 接口分组-测试接口
     *
     * @return
     */
    @Bean
    public GroupedOpenApi testOpenApi() {
        String[] paths = {"/**"};
 
        String packagesToScan[] = {"com.accompany.controller"};
        return GroupedOpenApi.builder()
                .group("测试接口")
                .packagesToScan(packagesToScan)
                .pathsToMatch(paths)
                .build();
    }
 
     /**
     * 接口分组-通用接口
     *
     * @return
     */
    @Bean
    public GroupedOpenApi comatOpenApi() {
        String[] paths = {"/**"};
 
        String packagesToScan[] = {"com.accompany.controller"};
        return GroupedOpenApi.builder()
                .group("通用接口")
                .packagesToScan(packagesToScan)
                .pathsToMatch(paths)
                .build();
    }
 
 
 
}